	package charts ;
        import charts.series.Element;
	import hxjson2.JSON;
	
	class Factory
	{
		 var attach_right:Array<Dynamic>;

		public static function makeChart ( json:Dynamic ) : ObjectCollection
		{
			var collection: ObjectCollection = new ObjectCollection();
			
			// multiple bar charts all have the same X values, so
			// they are grouped around each X value, this tells
			// ScreenCoords how to group them:
			var bar_group: Float = 0;
			var name:String = '';
			var c : Int = 1;
			
			var elements:Array<Element> = json.elements; //cast(json['elements'],Array<Element>); // TODO - is there a need to specify the array parameter type?
			var element : Dynamic;
			
			for ( e in elements )
			{
				element = e;
				
				switch( element.type ) {
					case 'bar' :
						collection.add( new Bar( e, bar_group ) );
						bar_group++;
					case 'line':
						collection.add( new Line( e ) );
					case 'area':
						collection.add( new Area( e ) );
					case 'pie':
						collection.add( new Pie( e ) );
					case 'hbar':
						collection.add( new HBar( e ) );
						bar_group++;
					case 'bar_stack':
						collection.add( new BarStack( e, c, bar_group ) );
						bar_group++;
					case 'scatter':
						collection.add( new Scatter( e ) );
					case 'scatter_line':
						collection.add( new ScatterLine( e ) );
					case 'bar_sketch':
						collection.add( new BarSketch( e, bar_group ) );
						bar_group++;
					case 'bar_glass':
						collection.add( new BarGlass( e, bar_group ) );
						bar_group++;
					case 'bar_cylinder':
						collection.add( new BarCylinder( e, bar_group ) );
						bar_group++;
					case 'bar_cylinder_outline':
						collection.add( new BarCylinderOutline( e, bar_group ) );
						bar_group++;
					case 'bar_dome':
						collection.add( new BarDome( e, bar_group ) );
						bar_group++;
					case 'bar_round':
						collection.add( new BarRound( e, bar_group ) );
						bar_group++;
					case 'bar_round_glass':
						collection.add( new BarRoundGlass( e, bar_group ) );
						bar_group++;
					case 'bar_round3d':
						collection.add( new BarRound3D( e, bar_group ) );
						bar_group++;
					case 'bar_fade':
						collection.add( new BarFade( e, bar_group ) );
						bar_group++;
					case 'bar_3d':
						collection.add( new Bar3D( e, bar_group ) );
						bar_group++;
					case 'bar_filled':
						collection.add( new BarOutline( e, bar_group ) );
						bar_group++;
					case 'bar_plastic':
						collection.add( new BarPlastic( e, bar_group ) );
						bar_group++;
					case 'bar_plastic_flat':
						collection.add( new BarPlasticFlat( e, bar_group ) );
						bar_group++;
					case 'shape':
						collection.add( new Shape( e ) );
					case 'candle':
						collection.add( new Candle( e, bar_group ) );
						bar_group++;
				}
			}
			/*
					
			
				else if ( lv['candle' + name] != null )
				{
					ob = new BarCandle(lv, c, bar_group);
					bar_group++;
				}
				
			*/
		
			var y2:Bool = false; // TODO - wtf is this doing here?
			var y2lines:Array<String>; // TODO - wtf is this doing here?
			
			//
			// some data sets are attached to the right
			// Y axis (and min max)
			//
		//			this.attach_right = new Array<String>();
				
		//			if( lv.show_y2 != null )
		//				if( lv.show_y2 != 'false' )
		//					if( lv.y2_lines != null )
		//					{
		//						this.attach_right = lv.y2_lines.split(",");
		//					}
			
			collection.groups = bar_group;
			return collection;
		}
	}
